<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function() {
            $.post("<?= site_url() ?>setup/update_data_table", {
                det_id    : $('#det_id').val(), 
				doc_id	  : $('#doc_id').val(), 
				doc_induk : $('#doc_induk').val(), 
				status_id : $('#status_id').val(), 
				det_type_price : $('#det_type_price').val(), 
				type      : $('#type').val(),  
				satuan    : $('#satuan').val(),  
				qty_awal  : $('#qty_awal').val(), 
				qty_akhir : $('#qty_akhir').val(),  
				currency  : $('#currency').val(),  
				price	  : $('#price').val(),  
				penagihan : $('#penagihan').val() 
            },
            function(data) {
                $('#loader').html(data);
            });
        }
    });
	
    $(document).ready(function() {
        $("#formuser").keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $.validator.setDefaults({
                    submitHandler: function() {
                        $.post("<?= site_url() ?>setup/update_data_table", {
                            det_id    : $('#det_id').val(), 
							doc_id	  : $('#doc_id').val(), 
							doc_induk : $('#doc_induk').val(), 
							status_id : $('#status_id').val(), 
							det_type_price : $('#det_type_price').val(), 
							type      : $('#type').val(),  
							satuan    : $('#satuan').val(),  
							qty_awal  : $('#qty_awal').val(), 
							qty_akhir : $('#qty_akhir').val(),  
							currency  : $('#currency').val(),  
							price	  : $('#price').val(),  
							penagihan : $('#penagihan').val() 
                        },
                        function(data) {
                            $('#loader').html(data);
                        });
                    }
                });
            }
        });

        $("#formuser").validate();
    });

    function cancel(det_id, doc_id, doc_induk, status_id) {
        $.post("<?= site_url() ?>setup/edit_contract", {det_id: det_id, doc_id: doc_id, doc_induk: doc_induk, status_id: status_id}, function(data) {
			$('#loader').html(data);
        });
    }

</script>

<form method="post" id="formuser" action="#" enctype="multipart/form-data" class="form-horizontal" role="form">
	<div class="col-md-offset-1">
		<div class="col-md-11">
			<div class="panel-body well">
				<h4><b class="caret"></b><b> Form - Edit Table Price</b></h4>
            <?php if (isset($detail_data_table) && !empty($detail_data_table)) { ?>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_type" class="control-label">Type<span style="color:red;">*</span></label></div>
					<div class="col-sm-7">
						<select id="type" class="form-control input-sm required">
						<?php
							foreach($type_select as $type_select => $key)
							{
						?>
								<option value="<?php echo $key['TYPE_PRICE_ID'] ?>"<?php echo (strtoupper($detail_data_table['TYPE_PRICE_ID']) == $key['TYPE_PRICE_ID']) ? 'selected' : ''; ?>><?php echo $key['TYPE_PRICE_DESC'] ?></option>
						<?php		
							}
						?>							
						</select>
					</div>
				</div>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_satuan" class="control-label">Satuan<span style="color:red;">*</span></label></div>
					<div class="col-sm-3">
						<select id="satuan" class="form-control input-sm required">
						<?php
							foreach($satuan_select as $satuan_select => $key)
							{ 
						?>
								<option value="<?php echo $key['TYPE_SATUAN_NAME'] ?>"<?php echo (strtoupper($detail_data_table['DET_SATUAN']) == $key['TYPE_SATUAN_NAME']) ? 'selected' : ''; ?>><?php echo $key['TYPE_SATUAN_NAME'] ?></option>
						<?php	
							}
						?>			
						</select>
					</div>
				</div>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_qty_awal" class="control-label">Qty Awal</label></div>
					<div class="col-sm-3">
					<input type="text" class="form-control input-sm" id="qty_awal" value="<?php echo $detail_data_table['DET_QTY_AWAL']; ?>">
					</div>					
				</div>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_qty_akhir" class="control-label">Qty Akhir</label></div>
					<div class="col-sm-3">
					<input type="text" class="form-control input-sm" id="qty_akhir" value="<?php echo $detail_data_table['DET_QTY_AKHIR']; ?>">
					</div>					
				</div>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_currency" class="control-label">Currency<span style="color:red;">*</span></label></div>
					<div class="col-sm-3">
						<select id="currency" class="form-control input-sm required">
							<option value="US"<?php echo (strtoupper($detail_data_table['DET_PRICE_UNIT']) == 'US') ? 'selected' : ''; ?>>US$</option>
                            <option value="RP"<?php echo (strtoupper($detail_data_table['DET_PRICE_UNIT']) != 'US') ? 'selected' : ''; ?>>RP</option>
						</select>
					</div>
				</div>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_price" class="control-label">Price</label></div>
					<div class="col-sm-3">
					<input type="text" class="form-control input-sm" id="price" value="<?php echo $detail_data_table['DET_PRICE']; ?>">
					</div>					
				</div>
				<div class="col-sm-8">
					<div class="col-sm-4"><label for="l_penagihan" class="control-label">Penagihan<span style="color:red;">*</span></label></div>
					<div class="col-sm-3">
						<select id="penagihan" class="form-control input-sm required">
							<option value="BULAN"<?php echo (strtoupper($detail_data_table['DET_PENAGIHAN']) == 'BULAN') ? 'selected' : ''; ?>>Bulanan</option>
                            <option value="TAHUN"<?php echo (strtoupper($detail_data_table['DET_PENAGIHAN']) != 'BULAN') ? 'selected' : ''; ?>>Tahunan</option>
						</select>
					</div>
				</div>
				<div class="col-sm-8" style="padding-bottom: 10px;">
					<div class="col-sm-4">
						&nbsp;
					</div>
				</div>
				<div class="col-sm-8">
                    <div class="col-sm-4"><label for="button" class="control-label">&nbsp;</label></div>
                    <div class="col-sm-4">
                        <input type="hidden" id="det_id" value="<?php echo $detail_data_table['DET_ID']; ?>" />
						<input type="hidden" id="det_type_price" value="<?php echo $detail_data_table['DET_TYPE_PRICE']; ?>" />		
						
						<input type="hidden" id="doc_id" value="<?php echo $doc_id; ?>" />
						<input type="hidden" id="doc_induk" value="<?php echo $doc_induk; ?>" />
						<input type="hidden" id="status_id" value="<?php echo $status_id; ?>" />
										
                        <button type="submit" class="btn btn-success btn-block"><!--span class="glyphicon glyphicon-saved"></span--> Save Edit</button>
                    </div>
                    <div class="col-sm-4">
                        <button type="button" class="btn btn-default btn-block" onclick="cancel('<?php echo $det_id; ?>','<?php echo $doc_id; ?>','<?php echo $doc_induk; ?>','<?php echo $status_id; ?>');">
						<!--span class="glyphicon glyphicon-circle-arrow-left"></span--> Cancel</button>
                    </div>
                </div>
            <?php } //end if ?>
			</div>
        </div>
	</div>
</form>
	